package com.jxb.test20241216;

import java.util.LinkedList;
import java.util.Queue;

import com.jxb.tree.TreeNode;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/12/22 23:32
 **/
public class MaximumDepth_104 {

    public static void main(String[] args) {

    }

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
    }


    public int maxDepthWithQueue(TreeNode root) {
        if (root == null) {
            return 0;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        //深度
        int deep = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                TreeNode node = queue.poll();
                if (node.left != null) {
                    queue.offer(node.left);
                }
                if (node.right != null) {
                    queue.offer(node.right);
                }
                size--;
            }
            deep++;
        }
        return deep;
    }

}
